package com.recsmile.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.recsmile.bo.User;

@Controller
public class IndexController {

	
	@RequestMapping(value="/login")
	public String login(User user){
		UsernamePasswordToken token = new UsernamePasswordToken(user.getAccount(), user.getPassword());
		token.setRememberMe(true);
		try {
			SecurityUtils.getSubject().login(token);
			return "redirect:/main";
		} catch (AuthenticationException e) {
			e.printStackTrace();
			token.clear();
			return "redirect:/login";
		}
	}
}
